package com.mystyle.le.weekproject.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mystyle.le.weekproject.R;
import com.mystyle.le.weekproject.beans.DetialList;

import java.util.List;

/**
 * Created by le on 2016/10/11.
 */
public class DetialAdapter extends BaseAdapter {
    private List<DetialList> lists;
    private Context context;

    public DetialAdapter(List<DetialList> lists, Context context) {
        this.lists = lists;
        this.context = context;
    }

    @Override
    public int getCount() {
        return lists==null?0:lists.size();
    }

    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.detial_layout,parent,false);
            holder = new ViewHolder();
            holder.detial_content = (TextView) convertView.findViewById(R.id.detial_content);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        DetialList detialList = lists.get(position);
        String title = detialList.getTitle();
        holder.detial_content.setText(title);
        if (position!=-1){
            if (position%2==0){
                convertView.setBackgroundColor(Color.GRAY);
            }else {
                convertView.setBackgroundColor(Color.WHITE);
            }
            this.notifyDataSetChanged();
        }
        return convertView;
    }

//    /*
//    * 在getViewTypeCount中指定一共有几种不同的item
//    * */
//    @Override
//    public int getViewTypeCount() {
//        return lists.size();
//
//    }
//
//    /*
//    * 在getItemViewType(int position)中需要依据position的不同 返回不同的Type.
//    * */
//    @Override
//    public int getItemViewType(int position) {
//        return super.getItemViewType(position);
//    }

    class ViewHolder{
        TextView detial_content;
    }

}
